<?php
/**
 * author: Administrator
 * Createtime: 2015/9/2910:06
 * description: 
 */

namespace App\Http\Controllers;

use DB;

class TableController extends Controller
{
    public function getIndex()
    {
       /* DB::table('users')->insert([
            ['id'=>1,'name'=>'Laravel','email'=>'laravel@test.com','password'=>'123'],
            ['id'=>2,'name'=>'Academy','email'=>'academy@test.com','password'=>'123'],
            ['id'=>3,'name'=>'LaravelAcademy','email'=>'laravel-academy@test.com','password'=>'123']
        ]);*/
/*        $insaertId = DB::table('users')->insertGetId(
            ['name'=>'Laravel-Academy', 'email'=>'310@qq.com','password'=>'456']
        );
        echo $insaertId;*/

//        $users = DB::table('users')->select('name','email')->get();
/*        $users = DB::table('users')->where('name','Laravel')->first();
        dd($users);*/

        /*$affected = DB::table('users')->where('name','Laravel-Academy')->update(['password'=>'123']);
        echo $affected;*/
//        $deleted = DB::table('users')->where('id','>','3')->delete(); echo $deleted;
/*        DB::table('users')->chunk(2, function($users) {
            foreach ($users as $user) {
                echo $user->name."<br>";
            }
        });*/
        /*$users = DB::table('users')->lists('name');
        dd($users);*/
        $users = DB::table('users')->select(DB::Raw('name,email'))->where('id','<','3')->get();
        dd($users);
    }

    public function getJoin()
    {
        /*$users = DB::table('users')->join('posts','users.id','=','posts.user_id')->get();
        dd($users);*/
        /*$users = DB::table('users')->leftjoin('posts','users.id','=','posts.user_id')->get();
        dd($users);*/
/*        $users = DB::table('users')->join('posts', function ($join) {
            $join->on('users.id','=','posts.user_id')
                ->where('posts.id','>','3');
        })->get();
        dd($users);*/

       /* $users = DB::table('users')->where('id','<','3');
        $users = DB::table('users')->where('id','>',2)->union($users)->get();*/
        /*$user = DB::table('users')->where('name','Laravel')->orWhere('name','Academy')->get();
        dd($user);*/

        /*$users = DB::table('users')->orderBy('id','desc')->get();
        dd($users);*/
        /*$posts = DB::table('posts')->select('cat_id',DB::raw('count(id) as num '))->groupBy('cat_id')->get();
        dd($posts);*/

        /*$posts = DB::table('posts')->select('cat_id',DB::raw('SUM(views) as views'))->groupBy('cat_id')->having('views','>','500')->get();
        dd($posts);*/

        $posts = DB::table('posts')->skip(0)->take(2)->get();
        dd($posts);
    }
}